package com.hr;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.write.WritableWorkbook;

import com.alibaba.fastjson.JSONObject;
import com.conf.OAConfig;
import com.dal.Common;
import com.data.WorkItem;
import com.db.DBConnection;
import com.seeyon.client.CTPRestClient;
import com.seeyon.client.CTPServiceClientManager;

public class HRMainDal {
	
	public static void main(String[] args) {
		try {
			SimpleDateFormat sf2=new SimpleDateFormat("yyyy-MM-dd");
			Calendar calendar = Calendar.getInstance();
	        calendar.setTime(sf2.parse("2023-01-01"));
	        calendar.add(Calendar.MONTH, 14);
	        calendar.add(Calendar.DAY_OF_WEEK, -1);
	        System.out.println(sf2.format(calendar.getTime()));
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
	}
	
	public void OaInfoTb(){
		//创建连接sewoa
		Connection conn=new DBConnection().getDefConn();
		//创建连接Hr
		Connection hrconn=new DBConnection().getHrConn();
		Statement stmt=null;
		Statement hrstmt=null;
		try {
			stmt=conn.createStatement();
			hrstmt=hrconn.createStatement();
			
			StringBuffer insertLog = new StringBuffer();
			StringBuffer insertDB = new StringBuffer();
			
			//hrlog
			SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			SimpleDateFormat sf2=new SimpleDateFormat("yyyyMMddHHmmss");
			String modifyDate=sf.format(new Date());
			//查询sewoa库猴子那个hrlog表 类型= 底表信息同步
			ResultSet res=stmt.executeQuery("select createdate from hrlog where type='底表信息同步'");
			while (res.next()) {
				modifyDate=res.getString(1);
			}
			//删除sewoa库猴子那个hrlog表 类型= 底表信息同步
			stmt.executeUpdate("delete from hrlog where type='底表信息同步'");
			//创建sewoa库猴子那个hrlog表 类型= 底表信息同步
			stmt.executeUpdate("insert into hrlog(type,createdate) values ('底表信息同步',getdate())");
			
			//排班审核
			//查询formmain_0571 连接 col_summary（协同表）数据
			String sql="select f.id,field0097 排班表编码,c.id colId,c.start_date 发起时间 from formmain_0571 f,col_summary c " +
					"where c.FORM_RECORDID=f.id and f.id not in (select id from hrlog where type='排班审核') and c.state=3 ";
			res=stmt.executeQuery(sql);
			//循环数据
			while (res.next()) {
				//创建 新增数据sql
				insertLog.append("insert into hrlog(id,type,createdate)values('"+res.getString("id")+"','排班审核',getdate());");
				try {
					//路径
					String path="D:/Seeyon/A8/ApacheJetspeed/webapps/third/workSheet/";
					//附件集合
					List<String> fileNames = down(res.getString("colId"),path);
					//循环附件集合
					for (int i = 0; i < fileNames.size(); i++) {
						//创建排班表信息
						insertDB.append("insert into oa_worksheet(sheetcode,pbblj,approvaltime," +
								"atsid,flag,logtime) " +
								"values ('','"+OAConfig.oa_Ip+"third/workSheet/"+fileNames.get(i)+"',getdate()," +
										"'101','0',getdate());");
						//initExcel(fileNames.get(i),insertDB);
					}
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
			}
			//特殊假别档案
			//查询formmain_0610 连接 人员表（org_member）
			sql="select f.id,m.code 员工工号,m.name 员工姓名,field0039 考勤日期,field0040 打卡时间,field0041 进出标记,field0043 操作类别 " +
					"from formmain_0610 f,org_member m " +
					"where field0016=m.id and field0061='1' and (field0062='' or field0062 is null) ";
			res=stmt.executeQuery(sql);
			while (res.next()) {
				//创建员工打卡记录信息
				insertDB.append("insert into oa_emporiginaldata(empcode,c_name,att_date," +
						"att_datetime,inorout,operationtype," +
						"atsid,flag,logtime) " +
						"values ('"+nullToObject(res.getString("员工工号"))+"','"+nullToObject(res.getString("员工姓名"))+"','"+nullToObject(res.getString("考勤日期"))+"'," +
								"'"+nullToObject(res.getString("打卡时间"))+"','"+nullToObject(res.getString("进出标记"))+"','"+nullToObject(res.getString("操作类别"))+"'," +
								"'101','0',getdate());");
				//修改OA排班审核信息
				insertLog.append("update formmain_0610 set field0062='"+sf2.format(new Date())+"同步完成' where id ="+res.getString("id")+";");
			}
			//员工加班信息表
			//查询formmain_0606 连接 枚举表（formmain_0606） 连接人员表（org_member）
			sql="select f.id,m.code 员工工号,m.name 员工姓名,field0003 考勤日期,i.code 加班类型,field0006 加班小时数,field0014 发薪日期, " +
					"field0007 加班开始时间,field0008 加班结束时间,field0009 加班原因,isnull(field0011,0) 是否历史 " +
					"from formmain_0606 f " +
					"left outer join CTP_ENUM_ITEM i on i.id=field0004 " +
					",org_member m " +
					"where f.field0001=m.id and (field0015='' or field0015 is null) ";
			res=stmt.executeQuery(sql);
			//循环查询到的数据
			while (res.next()) {
				//判断是否历史 = 1
				if(res.getString("是否历史").equals("1")){
					//创建员工历史加班单数据
					insertDB.append("insert into oa_hisempotsheet(empcode,c_name,att_date," +
							"ottype,ottime,begintime,endtime,payrolldate," +
							"notes,atsid,flag,logtime) " +
							"values ('"+nullToObject(res.getString("员工工号"))+"','"+nullToObject(res.getString("员工姓名"))+"','"+nullToObject(res.getString("考勤日期"))+"'," +
									"'"+nullToObject(res.getString("加班类型"))+"','"+nullToObject(res.getString("加班小时数"))+"','"+nullToObject(res.getString("加班开始时间"))+"','"+nullToObject(res.getString("加班结束时间"))+"','"+nullToObject(res.getString("发薪日期"))+"'," +
									"'"+nullToObject(res.getString("加班原因"))+"','101','0',getdate());");
				}else{
					//创建员工加班单表数据
					insertDB.append("insert into oa_empotsheet(empcode,c_name,att_date," +
							"ottype,ottime,begintime,endtime," +
							"notes,atsid,flag,logtime) " +
							"values ('"+nullToObject(res.getString("员工工号"))+"','"+nullToObject(res.getString("员工姓名"))+"','"+nullToObject(res.getString("考勤日期"))+"'," +
									"'"+nullToObject(res.getString("加班类型"))+"','"+nullToObject(res.getString("加班小时数"))+"','"+nullToObject(res.getString("加班开始时间"))+"','"+nullToObject(res.getString("加班结束时间"))+"'," +
									"'"+nullToObject(res.getString("加班原因"))+"','101','0',getdate());");
				}
				//修改OA员工加班信息表数据
				insertLog.append("update formmain_0606 set field0015='"+sf2.format(new Date())+"同步完成' where id ="+res.getString("id")+";");
			}
			//请休假/消假档案
			//查询formmain_0588 连接 人员表（org_member） 连接 枚举档案表（CTP_ENUM_ITEM）
			sql="select f.id,field0018 请假单编号,field0030 销假单编号,m.code 员工工号,m.name 员工姓名,i.code 假别,field0023 请假小时数," +
				"field0024 请假开始时间,field0025 请假结束时间,field0026 请假公出原因,field0031 单据类型,field0041 孩子生日  " +
				"from formmain_0588 f,org_member m,CTP_ENUM_ITEM i " +
				"where m.id=field0016 and i.id=field0022 and (field0042='' or field0042 is null) ";
			res = stmt.executeQuery(sql);
			//循环查询到的数据
			while (res.next()) {
				//当单据类型！=空 并且 单据类型 = 正常
				if(res.getString("单据类型")!=null && res.getString("单据类型").equals("正常"))
					//创建员工请假单数据信息
					insertDB.append("insert into oa_empleavesheet(sheetcode,empcode,c_name," +
							"leavetype,leavetime,begintime,endtime,childrenbirthday," +
							"notes,atsid,flag,logtime) " +
							"values ('"+res.getString("请假单编号")+"','"+nullToObject(res.getString("员工工号"))+"','"+res.getString("员工姓名")+"'," +
									"'"+res.getString("假别")+"','"+nullToObject(res.getString("请假小时数"))+"','"+nullToObject(res.getString("请假开始时间"))+"','"+nullToObject(res.getString("请假结束时间"))+"','"+nullToObject(res.getString("孩子生日"))+"'," +
									"'"+nullToObject(res.getString("请假公出原因"))+"','101','0',getdate());");
				else
					//创建员工销假单数据信息
					insertDB.append("insert into oa_empqxleavesheet(sheetcode,empcode,c_name," +
							"leavetype,leavetime,begintime,endtime," +
							"notes,atsid,flag,logtime) " +
							"values ('"+res.getString("销假单编号")+"','"+nullToObject(res.getString("员工工号"))+"','"+res.getString("员工姓名")+"'," +
									"'"+res.getString("假别")+"','"+nullToObject(res.getString("请假小时数"))+"','"+nullToObject(res.getString("请假开始时间"))+"','"+nullToObject(res.getString("请假结束时间"))+"'," +
									"'"+nullToObject(res.getString("请假公出原因"))+"','101','0',getdate());");
				//修改formmain_0588（请休假/消假档案） 表数据
 				insertLog.append("update formmain_0588 set field0042='"+sf2.format(new Date())+"同步完成' where id ="+res.getString("id")+";");
			}

			//员工配偶档案  modify_date
			//查询formmain_0609（员工配偶档案表） 连接 ORG_MEMBER（人员表）
			sql="select f.id,m.code 员工工号,m.name 员工姓名,field0001 配偶姓名,field0008 配偶生日,field0014 配偶手机," +
					"field0018  配偶工作单位,field0019  配偶工作岗位 " +
					"from formmain_0609 f,ORG_MEMBER m " +
					"where f.field0006=m.id and (field0020='' or field0020 is null) ";
			res=stmt.executeQuery(sql);
			//循环查询到的数据
			while (res.next()) {
				//创建HrP中间库员工配偶信息数据
				insertDB.append("insert into oa_empspousesheet(empcode,c_name,poname," +
						"pomarredate,pomobile," +
						"pocompanyname,potitle," +
						"atsid,flag,logtime) " +
						"values ('"+nullToObject(res.getString("员工工号"))+"','"+nullToObject(res.getString("员工姓名"))+"','"+nullToObject(res.getString("配偶姓名"))+"'," +
								"'"+nullToObject(res.getString("配偶生日"))+"','"+nullToObject(res.getString("配偶手机"))+"'," +
								"'"+nullToObject(res.getString("配偶工作单位"))+"','"+nullToObject(res.getString("配偶工作岗位"))+"'," +
								"'101','0',getdate());");
				//修改formmain_0609（员工配偶档案表）数据信息
				insertLog.append("update formmain_0609 set field0020='"+sf2.format(new Date())+"同步完成' where id ="+res.getString("id")+";");
			}
			
			//老年人护理假限额档案
			//formmain_0596（老年人护理假限额档案） 连接 枚举档案表（CTP_ENUM_ITEM）
			sql="select f.id,m.code 员工工号,m.name 员工姓名,field0051 存在标识,field0029 年度," +
					"case i.SHOWVALUE when '是' then 1 else 0 end 是否独生子女 " +
					"from formmain_0596 f " +
					"left outer join CTP_ENUM_ITEM i on i.id=field0049 " +
					",ORG_MEMBER m " +
					"where m.id=field0026 and (field0066='' or field0066 is null) ";
			res=stmt.executeQuery(sql);
			//循环数据
			while (res.next()) {
				//创建Hrp系统员工老年人护理信息数据
				insertDB.append("insert into oa_empoldnursheet(empcode,c_name," +
						"empfmyear,empisdszn,empyear," +
						"atsid,flag,logtime) " +
						"values ('"+nullToObject(res.getString("员工工号"))+"','"+res.getString("员工姓名")+"'," +
								"'"+nullToObject(res.getString("存在标识"))+"','"+nullToObject(res.getString("是否独生子女"))+"','"+nullToObject(res.getString("年度"))+"'," +
								"'101','0',getdate());");
				//修改OA表中老年人护理假限额档案 信息数据
				insertLog.append("update formmain_0596 set field0066='"+sf2.format(new Date())+"同步完成' where id ="+res.getString("id")+";");
			}
			
			//员工子女档案
			//查询formmain_0595（员工子女档案） 连接 人员表 （ORG_MEMBER）
			sql="select f.id,m.code 员工工号,m.name 员工姓名,field0001 孩子姓名,field0008 出生日期 " +
					"from formmain_0595 f,ORG_MEMBER m " +
					"where m.id=field0006 and (field0019='' or field0019 is null) ";
			res=stmt.executeQuery(sql);
			//循环数据
			while (res.next()) {
				//创建Hrp系统员工子女档案 信息
				insertDB.append("insert into oa_empchildrensheet(empcode,c_name," +
						"childrenname,childrenbirthday," +
						"atsid,flag,logtime) " +
						"values ('"+nullToObject(res.getString("员工工号"))+"','"+res.getString("员工姓名")+"'," +
								"'"+nullToObject(res.getString("孩子姓名"))+"','"+nullToObject(res.getString("出生日期"))+"'," +
								"'101','0',getdate());");
				//修改OA系统中的员工子女档案信息数据
				insertLog.append("update formmain_0595 set field0019='"+sf2.format(new Date())+"同步完成' where id ="+res.getString("id")+";");
				
			}
			
			//班车到场时间汇总
			//查询formmain_0582（班车到场时间汇总） 连接 枚举档案表（CTP_ENUM_ITEM）
			sql="select f.id,i1.SHOWVALUE 厂区,field0014 考勤日期,i2.SHOWVALUE 班次,field0008 最后到场时间 " +
					"from formmain_0582 f,CTP_ENUM_ITEM i1,CTP_ENUM_ITEM i2 " +
					"where f.field0007=i1.id and field0001=i2.id and (field0015='' or field0015 is null) ";
			res=stmt.executeQuery(sql);
			//循环数据
			while (res.next()) {
				//创建Hrp班车表数据
				insertDB.append("insert into oa_bussheet(factoryarea,att_date," +
						"bclx,bustime," +
						"atsid,flag,logtime) " +
						"values ('"+nullToObject(res.getString("厂区"))+"','"+nullToObject(res.getString("考勤日期"))+"'," +
								"'"+nullToObject(res.getString("班次"))+"','"+nullToObject(res.getString("最后到场时间"))+"'," +
								"'101','0',getdate());");
				//修改OA系统中班车到场时间汇总 数据信息
				insertLog.append("update formmain_0582 set field0015='"+sf2.format(new Date())+"同步完成' where id ="+res.getString("id")+";");
			}
			if(!insertLog.toString().equals("")){
				//执行修改OA表数据
				stmt.executeUpdate(insertLog.toString());
			}
			if(!insertDB.toString().equals("")){
				//执行修改Hrp表数据
				hrstmt.executeUpdate(insertDB.toString());
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try {
				stmt.close();
				conn.close();
				hrstmt.close();
				hrconn.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}
	
	public void HrInfoTb(){
		//创建JDBC连接
		Connection conn=new DBConnection().getDefConn();
		//创建JDBC连接
		Connection hrconn=new DBConnection().getHrConn();
		Statement stmt=null;
		Statement hrstmt=null;
		try {
			stmt=conn.createStatement();
			hrstmt=hrconn.createStatement();

			//查询OA人员信息
			HashMap<String, String> member = new Common().initOA_Member();
			
			CTPServiceClientManager clientManager = CTPServiceClientManager.getInstance(OAConfig.rest_ip);
  	        CTPRestClient client = clientManager.getRestClient();
  	        client.authenticate(OAConfig.rest_user, OAConfig.rest_pw);
  	        Calendar calendar = Calendar.getInstance();
	        SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        SimpleDateFormat sf2=new SimpleDateFormat("yyyy-MM-dd");
	        calendar.setTime(new Date());
	        calendar.add(Calendar.MINUTE, -10);
	        String logtime=sf.format(calendar.getTime());
			//育儿假控制信息
			//查询Hrp系统数据育儿假控制信息数据
			String sql="select empcode 员工编码,c_name 员工姓名,year 年度,childrenbirthday 孩子出生日期,sjbegindate 实际年度开始日期," +
					" sjenddate 实际年度结束日期,xyts 享有天数,tzts 调整天数,yyts 已用天数,syts 剩余天数,childrenname 孩子姓名  " +
					" from oa_empchildcareleave where logtime>='"+logtime+"' ";
			ResultSet res=hrstmt.executeQuery(sql);
			//循环查询到的数据
			while (res.next()) {
				//根据在Hrp系统重查询到的员工编码在OA人员表中查找
				if(member.get(res.getString("员工编码"))==null){
					System.out.println("育儿假:"+res.getString("员工编码")+"-"+res.getString("员工姓名")+",未匹配到账户");
					//没找到进行下一次循环
					continue;
				}
					
				try {
					//修改OA系统育儿假档案信息
					int count=stmt.executeUpdate("update formmain_0586 set " +
							"field0032='"+nullToObject(res.getString("享有天数"))+"'," +
							"field0033='"+nullToObject(res.getString("调整天数"))+"'," +
							"field0034='"+nullToObject(res.getString("已用天数"))+"'," +
							"field0035='"+nullToObject(res.getString("剩余天数"))+"', " +
							"field0040='"+((res.getString("已用天数")==null?0:res.getInt("已用天数"))*8)+"' " +
	            			"  where field0014='"+res.getString("员工编码")+"' " +
	            			" and field0056 ='"+res.getString("孩子姓名")+"' " +
	            			" and field0050 ='"+sf2.format(sf.parse(res.getString("孩子出生日期")))+"' " +
	            			" and field0030 ='"+sf2.format(sf2.parse(res.getString("实际年度开始日期")))+"' " +
	            			" and field0031 ='"+sf2.format(sf2.parse(res.getString("实际年度结束日期")))+"' ");
	            	//如果没有修改数据则在OA系统中创建一条数据
					if(count==0){
	            		Element element,column,value;
	        			Document doc=DocumentHelper.createDocument();
	        			Element forms=doc.addElement("forms");
						forms.addAttribute("version", "2.1");
						Element root=forms.addElement("formExport");
						element=root.addElement("summary");
						element.addAttribute("id", "1309748970347515697");
						element.addAttribute("name", "formmain_0466");
						element=root.addElement("definitions");
						element.addAttribute("valuetype", "10");
						element.addAttribute("isnull", "true");
						element.addAttribute("length", "0");
						
						element=root.addElement("values");
						
						column=element.addElement("column");
						column.addAttribute("name", "员工工号");
						value=column.addElement("value");
						value.setText(res.getString("员工编码"));
						
						column=element.addElement("column");
						column.addAttribute("name", "员工姓名");
						value=column.addElement("value");
						value.setText(member.get(res.getString("员工编码")).split(",")[0]);
						
						column=element.addElement("column");
						column.addAttribute("name", "年度");
						value=column.addElement("value");
						value.setText(nullToObject(res.getString("年度"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "1990-01-01");
						value=column.addElement("value");
						value.setText("1990-01-01 00:00:00");
						
						column=element.addElement("column");
						column.addAttribute("name", "孩子出生日期");
						value=column.addElement("value");
						value.setText(sf2.format(sf.parse(res.getString("孩子出生日期")))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "孩子生日");
						value=column.addElement("value");
						value.setText(sf2.format(sf.parse(res.getString("孩子出生日期"))));
						
						column=element.addElement("column");
						column.addAttribute("name", "实际年度开始时间");
						value=column.addElement("value");
						value.setText(sf2.format(sf2.parse(res.getString("实际年度开始日期"))));
						
						column=element.addElement("column");
						column.addAttribute("name", "实际年度结束时间");
						value=column.addElement("value");
						value.setText(sf2.format(sf2.parse(res.getString("实际年度结束日期"))));
						
						column=element.addElement("column");
						column.addAttribute("name", "孩子姓名");
						value=column.addElement("value");
						value.setText(nullToObject(res.getString("孩子姓名"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "享有天数");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("享有天数"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "调整天数");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("调整天数"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "已用天数");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("已用天数"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "剩余天数");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("剩余天数"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "已用小时数");
						value=column.addElement("value");
						value.setText(((res.getString("已用天数")==null?0:res.getInt("已用天数"))*8)+"");
						
	            		Map para = new HashMap();
	            		para.put("templateCode", "yejkz01");
	            		para.put("loginName", "yysjs");
	            		para.put("dataXml", doc.asXML());
				    	
				    	String result=client.post("form/import/yejkz01",para, String.class);
	            	}
				} catch (Exception e) {
					e.printStackTrace();
					// TODO: handle exception
				}
			}
			
			//年假数据信息
			//查询Hrp系统中员工年假信息数据
			sql="select empcode 员工编码,c_name 员工姓名,year 年假年度,snnjzbngqr 上年年假在本年过期日,lastyearjzfdnj 上年法定年假小时," +
					"lastyearjzgsnj 上年公司年假小时,currentyearxyfdnj 本年法定年假小时,currentyearxygsnj 本年公司年假小时,bnysysnfdnj 本年已使用上年法定年假小时," +
					"bnysysngsnj 本年已使用上年公司年假小时,bnysybnfdnj 本年已使用本年法定年假小时,bnysybngsnj 本年已使用本年公司年假小时,lastyearsynjtz 上年年假调整小时," +
					"currentyearsynjtz 本年年假调整小时,lastyearsykyfdnj 上年剩余可用法定年假小时,lastyearsykygsnj 上年剩余可用公司年假小时,"+
					"currentyearsykyfdnj 本年剩余法定年假小时,currentyearsykygsnj 本年剩余公司年假小时," +
					"bnysynjhj 已用小时数,bnysynjhj 本年已使用年假小时合计,currentyearsykynjhj 本年剩余可用年假小时合计  " +
					"  from oa_empannualleave  where logtime>='"+logtime+"'";
			res=hrstmt.executeQuery(sql);
			//循环数据
			while (res.next()) {
				//根据在Hrp系统重查询到的员工编码在OA人员表中查找
				if(member.get(res.getString("员工编码"))==null){
					System.out.println("年假:"+res.getString("员工编码")+"-"+res.getString("员工姓名")+",未匹配到账户");
					//没找到进行下一次循环
					continue;
				}
		        calendar.setTime(sf2.parse(res.getString("年假年度")+"-01-01"));
		        calendar.add(Calendar.MONTH, 14);
		        calendar.add(Calendar.DAY_OF_WEEK, -1);
				try {
					//修改OA系统中的年假档案数据
					int count=stmt.executeUpdate("update formmain_0585 set " +
							"field0021='"+nullToObject(res.getString("上年年假在本年过期日"))+"'," +
							"field0022='"+nullToObject(res.getString("上年法定年假小时"))+"'," +
							"field0023='"+nullToObject(res.getString("上年公司年假小时"))+"'," +
							"field0024='"+nullToObject(res.getString("本年法定年假小时"))+"'," +
							"field0025='"+nullToObject(res.getString("本年公司年假小时"))+"'," +
							"field0036='"+nullToObject(res.getString("本年已使用上年法定年假小时"))+"'," +
							"field0050='"+nullToObject(res.getString("本年已使用上年公司年假小时"))+"'," +
							"field0051='"+nullToObject(res.getString("本年已使用本年法定年假小时"))+"'," +
							"field0052='"+nullToObject(res.getString("本年已使用本年公司年假小时"))+"'," +
							"field0037='"+nullToObject(res.getString("上年年假调整小时"))+"', " +
							"field0026='"+nullToObject(res.getString("本年年假调整小时"))+"', " +
							"field0038='"+nullToObject(res.getString("上年剩余可用法定年假小时"))+"', " +
							"field0039='"+nullToObject(res.getString("上年剩余可用公司年假小时"))+"', " +
							"field0040='"+nullToObject(res.getString("本年剩余法定年假小时"))+"', " +
							"field0041='"+nullToObject(res.getString("本年剩余公司年假小时"))+"', " +
							"field0043='"+nullToObject(res.getString("已用小时数"))+"', " +
							"field0053='"+nullToObject(res.getString("本年已使用年假小时合计"))+"', " +
							"field0027='"+nullToObject(res.getString("本年剩余可用年假小时合计"))+"', " +
							"field0046='"+res.getString("年假年度")+"-01-01 00:00"+"', " +
							"field0047='"+sf2.format(calendar.getTime())+" 23:59"+"' " +
	            			" where field0014='"+res.getString("员工编码")+"' ");
					//如果没有修改数据则在OA系统中创建一条数据
					if(count==0){
	            		Element element,column,value;
	        			Document doc=DocumentHelper.createDocument();
	        			Element forms=doc.addElement("forms");
						forms.addAttribute("version", "2.1");
						Element root=forms.addElement("formExport");
						element=root.addElement("summary");
						element.addAttribute("id", "1309748970347515697");
						element.addAttribute("name", "formmain_0466");
						element=root.addElement("definitions");
						element.addAttribute("valuetype", "10");
						element.addAttribute("isnull", "true");
						element.addAttribute("length", "0");
						
						element=root.addElement("values");
						
						column=element.addElement("column");
						column.addAttribute("name", "员工工号");
						value=column.addElement("value");
						value.setText(res.getString("员工编码"));
						
						column=element.addElement("column");
						column.addAttribute("name", "员工姓名");
						value=column.addElement("value");
						value.setText(member.get(res.getString("员工编码")).split(",")[0]);
						
						column=element.addElement("column");
						column.addAttribute("name", "所属年度");
						value=column.addElement("value");
						value.setText(nullToObject(res.getString("年假年度"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "1990-01-01");
						value=column.addElement("value");
						value.setText("1990-01-01 00:00:00");
						
						column=element.addElement("column");
						column.addAttribute("name", "上年年假在本年过期日");
						value=column.addElement("value");
						value.setText(sf2.format(sf2.parse(nullToObject(res.getString("上年年假在本年过期日"))+"")));
						
						column=element.addElement("column");
						column.addAttribute("name", "上年法定年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("上年法定年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "上年公司年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("上年公司年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "本年法定年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("本年法定年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "本年公司年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("本年公司年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "本年已使用上年法定年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("本年已使用上年法定年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "本年已使用上年公司年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("本年已使用上年公司年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "本年已使用本年法定年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("本年已使用本年法定年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "本年已使用本年公司年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("本年已使用本年公司年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "上年年假调整小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("上年年假调整小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "本年年假调整小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("本年年假调整小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "上年剩余可用法定年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("上年剩余可用法定年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "上年剩余可用公司年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("上年剩余可用公司年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "本年剩余法定年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("本年剩余法定年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "本年剩余公司年假小时");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("本年剩余公司年假小时"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "已用小时数");
						value=column.addElement("value");
						value.setText(res.getString("已用小时数"));
						
						column=element.addElement("column");
						column.addAttribute("name", "本年已使用年假小时合计");
						value=column.addElement("value");
						value.setText(res.getString("本年已使用年假小时合计"));
						
						column=element.addElement("column");
						column.addAttribute("name", "本年剩余可用年假小时合计");
						value=column.addElement("value");
						value.setText(res.getString("本年剩余可用年假小时合计"));
						
						column=element.addElement("column");
						column.addAttribute("name", "年假时限起");
						value=column.addElement("value");
						value.setText(res.getString("年假年度")+"-01-01 00:00:00");
						
						column=element.addElement("column");
						column.addAttribute("name", "年假时限止");
						value=column.addElement("value");
						value.setText(sf2.format(calendar.getTime())+" 23:59:00");
						
	            		Map para = new HashMap();
	            		para.put("templateCode", "njkz01");
	            		para.put("loginName", "yysjs");
	            		para.put("dataXml", doc.asXML());
				    	
				    	String result=client.post("form/import/njkz01",para, String.class);
	            	}
				} catch (Exception e) {
					e.printStackTrace();
					// TODO: handle exception
				}
			}
			
			//二十年奖励假档案
			//查询Hrp系统中的二十年奖励假档案信息
			sql="select empcode 员工编码,c_name 员工姓名,begindate 员工享有20年奖励假开始日期,enddate 员工享有20年奖励假结束日期,xyts 员工享有20年奖励假天数," +
					"yyts 员工已用20年奖励假天数,syts 员工剩余20年奖励假天数,tzts 员工20年奖励假调整天数 " +
					"  from oa_emprewardleave  where logtime>='"+logtime+"'";
			res=hrstmt.executeQuery(sql);
			//循环数据
			while (res.next()) {
				//根据在Hrp系统重查询到的员工编码在OA人员表中查找
				if(member.get(res.getString("员工编码"))==null){
					System.out.println("二十年:"+res.getString("员工编码")+"-"+res.getString("员工姓名")+",未匹配到账户");
					//没找到进行下一次循环
					continue;
				}
				try {
					//修改OA系统中的二十年奖励假档案档案数据
					int count=stmt.executeUpdate("update formmain_0594 set " +
							"field0024='"+nullToObject(res.getString("员工享有20年奖励假开始日期"))+"'," +
							"field0039='"+nullToObject(res.getString("员工享有20年奖励假结束日期"))+"'," +
							"field0023='"+nullToObject(res.getString("员工享有20年奖励假天数"))+"'," +
							"field0046='"+nullToObject(res.getString("员工20年奖励假调整天数"))+"'," +
							"field0037='"+nullToObject(res.getString("员工已用20年奖励假天数"))+"'," +
							"field0033='"+nullToObject(res.getString("员工剩余20年奖励假天数"))+"'," +
							"field0044='"+(Double.parseDouble(nullToInt(res.getString("员工已用20年奖励假天数")))*8)+"' " +
	            			"where field0014='"+res.getString("员工编码")+"' ");
					//如果没有修改数据则在OA系统中创建一条数据
					if(count==0){
	            		Element element,column,value;
	        			Document doc=DocumentHelper.createDocument();
	        			Element forms=doc.addElement("forms");
						forms.addAttribute("version", "2.1");
						Element root=forms.addElement("formExport");
						element=root.addElement("summary");
						element.addAttribute("id", "1309748970347515697");
						element.addAttribute("name", "formmain_0466");
						element=root.addElement("definitions");
						element.addAttribute("valuetype", "10");
						element.addAttribute("isnull", "true");
						element.addAttribute("length", "0");
						
						element=root.addElement("values");
						
						column=element.addElement("column");
						column.addAttribute("name", "员工工号");
						value=column.addElement("value");
						value.setText(res.getString("员工编码"));
						
						column=element.addElement("column");
						column.addAttribute("name", "员工姓名");
						value=column.addElement("value");
						value.setText(member.get(res.getString("员工编码")).split(",")[0]);
						
						column=element.addElement("column");
						column.addAttribute("name", "1990-01-01");
						value=column.addElement("value");
						value.setText("1990-01-01 00:00:00");
						
						column=element.addElement("column");
						column.addAttribute("name", "20年奖励假开始日期");
						value=column.addElement("value");
						value.setText(nullToObject(res.getString("员工享有20年奖励假开始日期"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "20年奖励假结束日期");
						value=column.addElement("value");
						value.setText(nullToObject(res.getString("员工享有20年奖励假结束日期"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "员工享有20年奖励假天数");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("员工享有20年奖励假天数"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "20年奖励假已用天数");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("员工已用20年奖励假天数"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "员工20年奖励假调整天数");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("员工20年奖励假调整天数"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "20年奖励假剩余天数");
						value=column.addElement("value");
						value.setText(nullToInt(res.getString("员工剩余20年奖励假天数"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "20年奖励假已休小时数");
						value=column.addElement("value");
						value.setText((Double.parseDouble(nullToInt(res.getString("员工已用20年奖励假天数")))*8)+"");
						
	            		Map para = new HashMap();
	            		para.put("templateCode", "20njlkz01");
	            		para.put("loginName", "yysjs");
	            		para.put("dataXml", doc.asXML());
				    	
				    	String result=client.post("form/import/20njlkz01",para, String.class);
	            	}
				} catch (Exception e) {
					e.printStackTrace();
					// TODO: handle exception
				}
			}
			
			//人员班次异常详情
			//查询Hrp系统中的人员班次异常详情信息
			sql="select empcode 员工编码,c_name 员工姓名,att_date 考勤日期,yclx 考勤异常类型  " +
					"  from oa_empatsabnormal  where logtime>='"+logtime+"'";
			res=hrstmt.executeQuery(sql);
			//循环数据
			while (res.next()) {
				//根据在Hrp系统重查询到的员工编码在OA人员表中查找
				if(member.get(res.getString("员工编码"))==null)
					//没找到进行下一次循环
					continue;
				try {
					//修改OA系统中的人员班次异常详情数据
					int count=stmt.executeUpdate("update formmain_0578 set " +
							" field0017='"+nullToObject(res.getString("考勤日期"))+"'," +
							" field0018='"+nullToObject(res.getString("考勤异常类型"))+"' " +
	            			" where field0016='"+res.getString("员工编码")+"' ");
					//如果没有修改数据则在OA系统中创建一条数据
					if(count==0){
	            		Element element,column,value;
	        			Document doc=DocumentHelper.createDocument();
	        			Element forms=doc.addElement("forms");
						forms.addAttribute("version", "2.1");
						Element root=forms.addElement("formExport");
						element=root.addElement("summary");
						element.addAttribute("id", "1309748970347515697");
						element.addAttribute("name", "formmain_0466");
						element=root.addElement("definitions");
						element.addAttribute("valuetype", "10");
						element.addAttribute("isnull", "true");
						element.addAttribute("length", "0");
						
						element=root.addElement("values");
						
						column=element.addElement("column");
						column.addAttribute("name", "工号");
						value=column.addElement("value");
						value.setText(res.getString("员工编码"));
						
						column=element.addElement("column");
						column.addAttribute("name", "人员姓名");
						value=column.addElement("value");
						value.setText(member.get(res.getString("员工编码")).split(",")[0]);
						
						column=element.addElement("column");
						column.addAttribute("name", "异常日期");
						value=column.addElement("value");
						value.setText(nullToObject(res.getString("考勤日期"))+"");
						
						column=element.addElement("column");
						column.addAttribute("name", "异常类型");
						value=column.addElement("value");
						value.setText(nullToObject(res.getString("考勤异常类型"))+"");
						
	            		Map para = new HashMap();
	            		para.put("templateCode", "ycxx01");
	            		para.put("loginName", "yysjs");
	            		para.put("dataXml", doc.asXML());
				    	
				    	String result=client.post("form/import/ycxx01",para, String.class);
	            	}
				} catch (Exception e) {
					e.printStackTrace();
					// TODO: handle exception
				}
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try {
				stmt.close();
				conn.close();
				hrstmt.close();
				hrconn.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}
	
	public List<String> down(String colId,String filePath){
		//创建jdbc连接
		Connection conn=new DBConnection().getDefConn();
		Statement stmt=null;
		ArrayList<String> path=new ArrayList<String>();
		try {
			SimpleDateFormat sf=new SimpleDateFormat("yyyyMMddHHmmss");
			stmt=conn.createStatement();
			URL url = new URL(OAConfig.rest_ip+"/seeyon/userToken.jsp");  
	        HttpURLConnection urlcon = (HttpURLConnection)url.openConnection();  
	        urlcon.connect();         //获取连接  
	        InputStream is_token = urlcon.getInputStream();  
	        BufferedReader buffer = new BufferedReader(new InputStreamReader(is_token));
	        StringBuffer bs = new StringBuffer();  
	        String l = null;  
	        while((l=buffer.readLine())!=null){  
	           bs.append(l);  
	        }  
	        is_token.close();
	        String token=bs.toString();
	        //查询附件表
			ResultSet res=stmt.executeQuery("select FILE_URL,FILENAME,createdate from CTP_ATTACHMENT " +
					" where ATT_REFERENCE="+colId+" ");
			while (res.next()) { 
				StringBuffer parameters = new StringBuffer();
				if(res.getString(2).indexOf(".")>=0){
					 parameters.append("fileId="+res.getString(1));
					 parameters.append("&token="+token); 
					 URL preUrl = null; 
					 URLConnection uc = null;
					 //oa下载附件地址
					 preUrl = new URL(OAConfig.rest_ip+"/seeyon/services/downloadService");
				     String s = parameters.toString(); 
				     uc = preUrl.openConnection(); 
				     uc.setDoOutput(true); 
				     uc.setUseCaches(false); 
				     uc.setRequestProperty("Content-Type", 
				       "application/x-www-form-urlencoded");
				     HttpURLConnection hc = (HttpURLConnection) uc;
				     hc.setRequestMethod("POST");
				     OutputStream os = hc.getOutputStream();
				     DataOutputStream dos = new DataOutputStream(os); 
				     dos.writeBytes(s); 
				     dos.flush(); 
				     dos.close();
				     //将下载的文件转换成流
				     InputStream is = hc.getInputStream();
				     byte[] temp = new byte[is.available()];
				     byte[] result = new byte[0];
				     int size = 0;
				     if(temp.length>0){
						while ((size = is.read(temp)) != -1) {
							byte[] readBytes = new byte[size];
							System.arraycopy(temp, 0, readBytes, 0, size);
							result = mergeArray(new byte[][] { result, readBytes });
						}
				     }
				     String time=sf.format(new Date());
				     path.add(res.getString(1)+res.getString(2));
				     /* 生成实体文件 */
					 FileOutputStream file = new FileOutputStream(filePath+res.getString(1)+res.getString(2));
					 file.write(result);
					
					 int index = 1;
					 int ch;
					 while ((ch = is.read()) != -1)
					 {
						 file.write(ch);
						 index++;
					 }
					 file.close();
				}
			}
			return path;
		}catch(Exception e){
			e.printStackTrace();
			return path;
		}finally {
			try {
				stmt.close();
				conn.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}
	
	public void initExcel(String filepath,StringBuffer insertDB){
		ArrayList<WorkItem> list=new ArrayList<WorkItem>();
		Connection conn=new DBConnection().getDefConn();
		Statement stmt=null;
		try {
			stmt=conn.createStatement();
			HashMap<String, String> member = new Common().initOA_Member();
			HashMap<String, String> workNo = new Common().initOA_WorkNo();
			HashMap<String, String> workType = new Common().initOA_WorkType();
			
			WorkbookSettings ws = new WorkbookSettings();
			ws.setGCDisabled(true);
			ws.setDrawingsDisabled(true);
			ws.setCellValidationDisabled(true);
			
			File file=new File(filepath);
			FileInputStream in=new FileInputStream(file);
			Workbook book= Workbook.getWorkbook(in,ws);
            Sheet sheet=book.getSheet(0);
            WorkItem work;
            Calendar calendar = Calendar.getInstance();
  	        SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
  	        
            if(sheet.getRows()>0){
            	for (int i = 1; i < sheet.getRows(); i++) {
            		for (int j = 9; j < sheet.getColumns(); j++) {
            			if(!sheet.getCell(j, i).getContents().equals("")){
            				if(member.get(sheet.getCell(0, i).getContents())!=null
            						&&workNo.get(sheet.getCell(j, i).getContents())!=null ){
            					
            					work=new WorkItem();
                        		work.set员工编码(sheet.getCell(0, i).getContents());
                        		work.set员工姓名(sheet.getCell(1, i).getContents());
                        		work.set员工ID(member.get(sheet.getCell(0, i).getContents()).split(",")[0]);
                				work.set排班日期(sheet.getCell(j, 0).getContents());
                				work.set班次名称(sheet.getCell(j, i).getContents());
                    			work.set排班班次(workNo.get(sheet.getCell(j, i).getContents()).split(",")[0]);
                    			work.set班次编码(workNo.get(sheet.getCell(j, i).getContents()).split(",")[1]);
                    			work.set开始跨天(workNo.get(sheet.getCell(j, i).getContents()).split(",")[4]);
                    			work.set结束跨天(workNo.get(sheet.getCell(j, i).getContents()).split(",")[5]);
                    			
                    			calendar.setTime(sf.parse(work.get排班日期()));
        						calendar.add(Calendar.DAY_OF_MONTH, Integer.parseInt(work.get开始跨天()==null?"0":work.get开始跨天()));
                    			work.set班次开始时间(sf.format(calendar.getTime())+" "+workNo.get(sheet.getCell(j, i).getContents()).split(",")[2]+":00");
                    			
                    			calendar.setTime(sf.parse(work.get排班日期()));
        						calendar.add(Calendar.DAY_OF_MONTH, Integer.parseInt(work.get结束跨天()==null?"0":work.get结束跨天()));
                    			work.set班次结束时间(sf.format(calendar.getTime())+" "+workNo.get(sheet.getCell(j, i).getContents()).split(",")[3]+":00");
                    			
                    			work.set班次类型(workType.get(sheet.getCell(j, 0).getContents())==null?"":workType.get(sheet.getCell(j, 0).getContents()));
                    			list.add(work);
            				}
            			}
					}
            	}
            }
            CTPServiceClientManager clientManager = CTPServiceClientManager.getInstance(OAConfig.rest_ip);
  	        CTPRestClient client = clientManager.getRestClient();
  	        client.authenticate(OAConfig.rest_user, OAConfig.rest_pw);
  	        
            for (int i = 0; i < list.size(); i++) {
            	work=list.get(i);
            	insertDB.append("insert into oa_empchangework(empcode,c_name,att_date," +
						"workhourid,work_cname," +
						"atsid,flag,logtime) " +
						"values ('"+nullToObject(work.get员工编码())+"','"+nullToObject(work.get员工姓名())+"','"+nullToObject(work.get排班日期())+"'," +
								"'"+nullToObject(work.get班次编码())+"','"+nullToObject(work.get班次名称())+"'," +
								"'101','0',getdate());");
            	try {
            		int count=stmt.executeUpdate("update formmain_0567 set field0001='"+work.get排班班次()+"'," +
                			"field0007='"+work.get班次类型()+"',field0008='"+work.get班次开始时间()+"'," +
                			"field0009='"+work.get班次结束时间()+"' " +
                			"where field0004='"+work.get员工编码()+"' and field0010='"+work.get排班日期()+"'");
                	if(count==0){
                		Element element,column,value;
            			Document doc=DocumentHelper.createDocument();
            			Element forms=doc.addElement("forms");
    					forms.addAttribute("version", "2.1");
    					Element root=forms.addElement("formExport");
    					element=root.addElement("summary");
    					element.addAttribute("id", "1309748970347515697");
    					element.addAttribute("name", "formmain_0466");
    					element=root.addElement("definitions");
    					element.addAttribute("valuetype", "10");
    					element.addAttribute("isnull", "true");
    					element.addAttribute("length", "0");
    					
    					element=root.addElement("values");
    					
    					column=element.addElement("column");
    					column.addAttribute("name", "工号");
    					value=column.addElement("value");
    					value.setText(work.get员工编码());
    					
    					column=element.addElement("column");
    					column.addAttribute("name", "姓名");
    					value=column.addElement("value");
    					value.setText(work.get员工ID());
    					
    					column=element.addElement("column");
    					column.addAttribute("name", "排班班次");
    					value=column.addElement("value");
    					value.setText(work.get排班班次());
    					
    					column=element.addElement("column");
    					column.addAttribute("name", "排班日期");
    					value=column.addElement("value");
    					value.setText(work.get排班日期());

    					column=element.addElement("column");
    					column.addAttribute("name", "班次开始时间");
    					value=column.addElement("value");
    					value.setText(work.get班次开始时间());
    					
    					column=element.addElement("column");
    					column.addAttribute("name", "班次结束时间");
    					value=column.addElement("value");
    					value.setText(work.get班次结束时间());
    					
    					
    					column=element.addElement("column");
    					column.addAttribute("name", "班次类型");
    					value=column.addElement("value");
    					value.setText(work.get班次类型());
                		
                		Map para = new HashMap();
                		para.put("templateCode", "pbbcxx01");
                		para.put("loginName", "yysjs");
                		para.put("dataXml", doc.asXML());
    			    	System.out.println(work.get排班日期());
    			    	String result=client.post("form/import/pbbcxx01",para, String.class);
                	}
				} catch (Exception e) {
					e.printStackTrace();
					// TODO: handle exception
				}
			}
            book.close();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally {
			try {
				stmt.close();
				conn.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}
	
	public byte[] mergeArray(byte[]... a) {  
        // 合并完之后数组的总长度  
        int index = 0;  
        int sum = 0;  
        for (int i = 0; i < a.length; i++) {  
            sum = sum + a[i].length;  
        }  
        byte[] result = new byte[sum];  
        for (int i = 0; i < a.length; i++) {  
            int lengthOne = a[i].length;  
            if(lengthOne==0){  
                continue;  
            }  
            // 拷贝数组  
            System.arraycopy(a[i], 0, result, index, lengthOne);  
            index = index + lengthOne;  
        }  
        return result;  
    }
	
	public Object nullToObject(Object obj){
		if(obj==null)
			return "";
		else
			return obj;
	}
	
	public String nullToInt(String obj){
		if(obj==null)
			return "0";
		else
			return obj;
	}
}
